\hypertarget{class_game_settings}{
\section{GameSettings Class Reference}
\label{class_game_settings}\index{GameSettings@{GameSettings}}
}


Persistent user preferences are stored to the game settings.  


\subsection*{Public Slots}
\begin{DoxyCompactItemize}
\item 
\hypertarget{class_game_settings_aa1788013c6d17648c6fc41dd31a46db5}{
Q\_\-INVOKABLE void \hyperlink{class_game_settings_aa1788013c6d17648c6fc41dd31a46db5}{save} ()}
\label{class_game_settings_aa1788013c6d17648c6fc41dd31a46db5}

\begin{DoxyCompactList}\small\item\em Saves settings to a SmashMiner.conf file. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_ac2e1b72e3e11b01583ef109559e77598}{
Q\_\-INVOKABLE void \hyperlink{class_game_settings_ac2e1b72e3e11b01583ef109559e77598}{resetToDefaults} ()}
\label{class_game_settings_ac2e1b72e3e11b01583ef109559e77598}

\begin{DoxyCompactList}\small\item\em Resets settings to a default values. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_aeddc2f730ea613581826c36f19a8eef9}{
void \hyperlink{class_game_settings_aeddc2f730ea613581826c36f19a8eef9}{setDifficultyLevel} (int)}
\label{class_game_settings_aeddc2f730ea613581826c36f19a8eef9}

\begin{DoxyCompactList}\small\item\em Setter for difficulty. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_adc2c46116b9d456d5e8d1642c5c841e5}{
void \hyperlink{class_game_settings_adc2c46116b9d456d5e8d1642c5c841e5}{setSteeringSensitivity} (int)}
\label{class_game_settings_adc2c46116b9d456d5e8d1642c5c841e5}

\begin{DoxyCompactList}\small\item\em Setter for steering sensitivity. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a1e527c9335a83a199b13efbc612f0ba9}{
void \hyperlink{class_game_settings_a1e527c9335a83a199b13efbc612f0ba9}{setMusicLevel} (int)}
\label{class_game_settings_a1e527c9335a83a199b13efbc612f0ba9}

\begin{DoxyCompactList}\small\item\em Setter for music level. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a86e04982ec68c06dfdc1bc1fe686f0d4}{
void \hyperlink{class_game_settings_a86e04982ec68c06dfdc1bc1fe686f0d4}{setSoundLevel} (int)}
\label{class_game_settings_a86e04982ec68c06dfdc1bc1fe686f0d4}

\begin{DoxyCompactList}\small\item\em Setter for sound level. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a92241e38bb8452bd085d0b2f84f67b46}{
void \hyperlink{class_game_settings_a92241e38bb8452bd085d0b2f84f67b46}{setLeftHanded} (bool)}
\label{class_game_settings_a92241e38bb8452bd085d0b2f84f67b46}

\begin{DoxyCompactList}\small\item\em Setter for left handedness. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a0dc6ae9ffb800a794937698e433f1290}{
void \hyperlink{class_game_settings_a0dc6ae9ffb800a794937698e433f1290}{setEndRewind} (bool)}
\label{class_game_settings_a0dc6ae9ffb800a794937698e433f1290}

\begin{DoxyCompactList}\small\item\em Setter for rewind mode. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{class_game_settings_a210d30d4b658aaabd7715d99e381c399}{GameSettings} (QObject $\ast$parent)
\begin{DoxyCompactList}\small\item\em Constructs \hyperlink{class_game_settings}{GameSettings}. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a0a021ae843688a10a443c0b1b1862415}{
void \hyperlink{class_game_settings_a0a021ae843688a10a443c0b1b1862415}{readHighScore} ()}
\label{class_game_settings_a0a021ae843688a10a443c0b1b1862415}

\begin{DoxyCompactList}\small\item\em Reads high scores from settings file. \item\end{DoxyCompactList}\item 
Q\_\-INVOKABLE int \hyperlink{class_game_settings_a4747f3d18177aba868b6f943a349b4e6}{setHighScore} (QString, int, QString)
\begin{DoxyCompactList}\small\item\em Sets new high score to its correct place to a high score list. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a4cea22317c38dd96baf1f502ee955df4}{
Q\_\-INVOKABLE bool \hyperlink{class_game_settings_a4cea22317c38dd96baf1f502ee955df4}{isHighScore} (int)}
\label{class_game_settings_a4cea22317c38dd96baf1f502ee955df4}

\begin{DoxyCompactList}\small\item\em Checks if {\itshape score\/} is new high score. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a4754c58fe31d10f39dcee299dd20e4f6}{
Q\_\-INVOKABLE \hyperlink{class_high_score_model}{HighScoreModel} $\ast$ \hyperlink{class_game_settings_a4754c58fe31d10f39dcee299dd20e4f6}{getHighScoreModel} ()}
\label{class_game_settings_a4754c58fe31d10f39dcee299dd20e4f6}

\begin{DoxyCompactList}\small\item\em Gets HighScore mode generated from settings high score. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hypertarget{class_game_settings_a75b35681f60b160a073c80437e0003e3}{
QSettings $\ast$ \hyperlink{class_game_settings_a75b35681f60b160a073c80437e0003e3}{settings}}
\label{class_game_settings_a75b35681f60b160a073c80437e0003e3}

\begin{DoxyCompactList}\small\item\em Game settings. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a0dc5338b1909e80ebcc6ea5a3bd9bac7}{
int \hyperlink{class_game_settings_a0dc5338b1909e80ebcc6ea5a3bd9bac7}{difficulty}}
\label{class_game_settings_a0dc5338b1909e80ebcc6ea5a3bd9bac7}

\begin{DoxyCompactList}\small\item\em Game difficulty level from 1-\/3, default = 2. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a538eef6a5221c2361f917d15a6422267}{
int \hyperlink{class_game_settings_a538eef6a5221c2361f917d15a6422267}{sensitivity}}
\label{class_game_settings_a538eef6a5221c2361f917d15a6422267}

\begin{DoxyCompactList}\small\item\em Game control (tilt) sensitivity from 1-\/10, default = 5. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a8c0fbcae08fd3d5415f7ff249dc8feff}{
int \hyperlink{class_game_settings_a8c0fbcae08fd3d5415f7ff249dc8feff}{musiclevel}}
\label{class_game_settings_a8c0fbcae08fd3d5415f7ff249dc8feff}

\begin{DoxyCompactList}\small\item\em Game music level from 0-\/10, default 6. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a203a88b28e1290d669907932f17f423b}{
int \hyperlink{class_game_settings_a203a88b28e1290d669907932f17f423b}{soundlevel}}
\label{class_game_settings_a203a88b28e1290d669907932f17f423b}

\begin{DoxyCompactList}\small\item\em Game sound effect level from 0-\/10, default 6. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a8be5c6f95aa4064663980e20508a27de}{
bool \hyperlink{class_game_settings_a8be5c6f95aa4064663980e20508a27de}{lefthanded}}
\label{class_game_settings_a8be5c6f95aa4064663980e20508a27de}

\begin{DoxyCompactList}\small\item\em Left handed mode, default false. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_a5e769635a0b42596cbc7c66f4471c174}{
bool \hyperlink{class_game_settings_a5e769635a0b42596cbc7c66f4471c174}{rewind}}
\label{class_game_settings_a5e769635a0b42596cbc7c66f4471c174}

\begin{DoxyCompactList}\small\item\em Rewind mode, default false. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_afbf0eedcdb6678dc47b1ac51ea55e44b}{
QList$<$ HighScore $>$ \hyperlink{class_game_settings_afbf0eedcdb6678dc47b1ac51ea55e44b}{highScoreList}}
\label{class_game_settings_afbf0eedcdb6678dc47b1ac51ea55e44b}

\begin{DoxyCompactList}\small\item\em Current high scores list. \item\end{DoxyCompactList}\item 
\hypertarget{class_game_settings_ad9bb22ab67b58c3002892c580b7caab0}{
\hyperlink{class_high_score_model}{HighScoreModel} $\ast$ \hyperlink{class_game_settings_ad9bb22ab67b58c3002892c580b7caab0}{highScoreModel}}
\label{class_game_settings_ad9bb22ab67b58c3002892c580b7caab0}

\begin{DoxyCompactList}\small\item\em Current high scores model. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Persistent user preferences are stored to the game settings. Settings contain values for music and sound effects level, difficulty, left handed mode, rewind mode and high scores. Class {\ttfamily \hyperlink{class_game_settings}{GameSettings}} is a container for these runtime user settings and it also loads settings from file when constructed and saves settings to file a when {\ttfamily \hyperlink{class_game_settings_aa1788013c6d17648c6fc41dd31a46db5}{save()}} method is called. Settings can be reseted to it's default values by calling {\ttfamily \hyperlink{class_game_settings_ac2e1b72e3e11b01583ef109559e77598}{resetToDefaults()}}. Class {\ttfamily \hyperlink{class_game_settings}{GameSettings}} also provides {\ttfamily \hyperlink{class_high_score_model}{HighScoreModel}} for the {\ttfamily \hyperlink{_high_scores_8qml}{HighScores.qml}} view.

Class {\ttfamily \hyperlink{class_game_settings}{GameSettings}} contains member {\ttfamily settings} which is instance of {\ttfamily QSettings}. {\ttfamily QSettings} is used to handle storing of the settings permanently and platform independently. On the {\ttfamily Unix} environments the actual game settings are stored under {\ttfamily $\sim$/}.config/Nokia/ to a file {\ttfamily SmashMiner.conf}. If {\ttfamily SmashMiner.conf} does not exist the default setting values are used.\hypertarget{class_game_settings_addingGameSettings}{}\subsection{Adding New Game Settings}\label{class_game_settings_addingGameSettings}
Here are the instructions how to add new game settings item and how it can be exposed to QML side. All settings values need to have signal to notify the value change, getter and setter and name and default value definitions.

Firs you must add a variable for your setting value. {\ttfamily \hyperlink{class_game_settings}{GameSettings}} contains each setting value as a member variable. Private member variable {\ttfamily bool} {\ttfamily lefthanded} is added to a {\ttfamily \hyperlink{gamesettings_8h_source}{gamesettings.h}:} 
\begin{DoxyCode}
private:
...
    bool lefthanded;
...
\end{DoxyCode}


Next some defines are needed. Settings value {\ttfamily bool} {\ttfamily lefthanded} has following defines at the {\ttfamily \hyperlink{gamesettings_8h_source}{gamesettings.h}:} 
\begin{DoxyCode}
...
#define GS_LEFT_HANDED "left_handed"
#define GS_LEFT_HANDED_DEFAULT false
...
\end{DoxyCode}
 The first define {\ttfamily GS\_\-LEFT\_\-HANDED} is the name of the setting to be used with {\ttfamily QSettings}. And second define {\ttfamily GS\_\-LEFT\_\-HANDED\_\-DEFAULT} is the default value.

Then at the constructor of the \hyperlink{class_game_settings}{GameSettings} the lefthanded value is loaded from the settings file by the name {\ttfamily GS\_\-LEFT\_\-HANDED}. If value does not exist the {\ttfamily GS\_\-LEFT\_\-HANDED\_\-DEFAULT} is used: 
\begin{DoxyCode}
...
lefthanded = settings->value(GS_LEFT_HANDED, GS_LEFT_HANDED_DEFAULT).toBool();
...
\end{DoxyCode}


Next we declare setter and getter for {\ttfamily lefthanded} to {\ttfamily \hyperlink{gamesettings_8h_source}{gamesettings.h}} as follows: 
\begin{DoxyCode}
...
inline bool leftHanded() { return lefthanded; }
...
void setLeftHanded(bool);
...
\end{DoxyCode}
 The getter {\ttfamily leftHanded()} is implemented to the header as a {\ttfamily inline} function.

Then we implement the {\ttfamily lefthanded} setter is to the {\ttfamily gamesettings.cpp}. 
\begin{DoxyCode}
...
void GameSettings::setLeftHanded(bool lefthanded)
{
    if (this->lefthanded != lefthanded) {
        this->lefthanded = lefthanded;
        emit leftHandedChanged(lefthanded);
    }
}
...
\end{DoxyCode}
 At the setter the new value is set and signal at the change is emitted only when the value changes. This prevents the unnecessary signal emittions.

Next we must declare the {\ttfamily leftHandedChanged(bool)} signal to the {\ttfamily \hyperlink{gamesettings_8h_source}{gamesettings.h}:} 
\begin{DoxyCode}
...
signals:
...
    void leftHandedChanged(bool);
...
\end{DoxyCode}


Then this signal is connected to the slot at the constructor of the {\ttfamily \hyperlink{class_game_widget}{GameWidget}:} 
\begin{DoxyCode}
...
connect(settings, SIGNAL(leftHandedChanged(bool)), this, SLOT(setLeftHandedness(b
      ool)));
...
\end{DoxyCode}


Class {\ttfamily \hyperlink{class_game_app_viewer}{GameAppViewer}} has member {\ttfamily \hyperlink{class_game_settings}{GameSettings}} {\ttfamily $\ast$settings};. Reference to {\ttfamily \hyperlink{class_game_settings}{GameSettings}} is given to {\ttfamily \hyperlink{class_game_widget}{GameWidget}} when constructed. Signal is emitted for {\ttfamily \hyperlink{class_game_widget}{GameWidget}} to slot {\ttfamily setLeftHandedness(bool)} when {\ttfamily lefthanded} value changes.\hypertarget{class_game_settings_exposingSettingsToQML}{}\subsubsection{Exposing settings to QML}\label{class_game_settings_exposingSettingsToQML}
Settings are used also from QML views. {\ttfamily \hyperlink{class_game_settings}{GameSettings}} instance is exposed to QML via context property {\ttfamily gameSettings} set at the {\ttfamily main.cpp:} 
\begin{DoxyCode}
...
context->setContextProperty("gameSettings", viewer.getSettings());
...
\end{DoxyCode}


Some changes are required to {\ttfamily \hyperlink{gamesettings_8h_source}{gamesettings.h}} to expose properties and methods to QML. For example {\ttfamily lefthanded} setting value is exposed to QML as property: 
\begin{DoxyCode}
...
Q_PROPERTY(bool leftHanded READ leftHanded WRITE setLeftHanded NOTIFY leftHandedC
      hanged)
...
\end{DoxyCode}


At the QML side the property can be used like any QML property: 
\begin{DoxyCode}
...
Switch {
        id: leftHandedSwitch

        width: buttonWidth
        height: buttonHeight
        onOnChanged: gameSettings.leftHanded = leftHandedSwitch.on
        Component.onCompleted: {
                if (gameSettings.leftHanded) {
                        leftHandedSwitch.state = "on";
                }
                else {
                        leftHandedSwitch.state = "off";
                }
        }
}
...
\end{DoxyCode}


If the property is changed from the QML side then the {\ttfamily NOTIFY} signal is emitted. Signal is connected at the C++ code to a slot and notification at the changed setting is received to the slot on C++ side.

For the {\ttfamily \hyperlink{_high_scores_8qml}{HighScores.qml}} view some public methods are exposed as invokables: 
\begin{DoxyCode}
...
Q_INVOKABLE int setHighScore(QString, int, QString);
Q_INVOKABLE bool isHighScore(int);
Q_INVOKABLE HighScoreModel* getHighScoreModel();
...
\end{DoxyCode}


For saving settings and resetting values from QML and two methods needs to be exposed: 
\begin{DoxyCode}
...
Q_INVOKABLE void save();
Q_INVOKABLE void resetToDefaults();
...
\end{DoxyCode}


Method {\ttfamily \hyperlink{class_game_settings_aa1788013c6d17648c6fc41dd31a46db5}{save()}} is called on {\ttfamily onBackClicked} slot when returning from settings QML view by pressing back button: 
\begin{DoxyCode}
...
    ViewFooter {
        id: settingsFooter

        width: parent.width
        height: headerHeight

        onBackClicked: {
            gameSettings.save();
            soundEngine.playMenuSound();
            back();
        }
...
\end{DoxyCode}
 

\subsection{Constructor \& Destructor Documentation}
\hypertarget{class_game_settings_a210d30d4b658aaabd7715d99e381c399}{
\index{GameSettings@{GameSettings}!GameSettings@{GameSettings}}
\index{GameSettings@{GameSettings}!GameSettings@{GameSettings}}
\subsubsection[{GameSettings}]{\setlength{\rightskip}{0pt plus 5cm}GameSettings::GameSettings (
\begin{DoxyParamCaption}
\item[{QObject $\ast$}]{ parent}
\end{DoxyParamCaption}
)}}
\label{class_game_settings_a210d30d4b658aaabd7715d99e381c399}


Constructs \hyperlink{class_game_settings}{GameSettings}. 

Initializes also QSettings and loads game settings from file. 

\subsection{Member Function Documentation}
\hypertarget{class_game_settings_a4747f3d18177aba868b6f943a349b4e6}{
\index{GameSettings@{GameSettings}!setHighScore@{setHighScore}}
\index{setHighScore@{setHighScore}!GameSettings@{GameSettings}}
\subsubsection[{setHighScore}]{\setlength{\rightskip}{0pt plus 5cm}int GameSettings::setHighScore (
\begin{DoxyParamCaption}
\item[{QString}]{ name, }
\item[{int}]{ score, }
\item[{QString}]{ time}
\end{DoxyParamCaption}
)}}
\label{class_game_settings_a4747f3d18177aba868b6f943a349b4e6}


Sets new high score to its correct place to a high score list. 

Removes the last score from list if list gets too long. 

The documentation for this class was generated from the following files:\begin{DoxyCompactItemize}
\item 
gamesettings.h\item 
gamesettings.cpp\end{DoxyCompactItemize}
